def divisor(n):
    divisors=[]
    for i in xrange(1,(n/2)+1):
        if n%i==0:
            divisors.append(i) 
    return divisors
def d(n):
    return sum(divisor(n))
def Amicable(n):
    if d(d(n))==n and d(n)!=n:
        return True
ans=[]
for i in xrange(1,10001):
    if Amicable(i):
        ans.append(i)
print sum(ans)
    
